package com.niji.littly_donkey_android.adapter;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.niji.littly_donkey_android.R;
import com.niji.littly_donkey_android.activity.ScreenDetailsActivity;
import com.niji.littly_donkey_android.bean.CheckCode;
import com.niji.littly_donkey_android.bean.Fans;
import com.niji.littly_donkey_android.util.NetworkGlideImageLoader;
import com.niji.littly_donkey_android.util.UrlUtil;
import com.niji.littly_donkey_android.view.CircleImageView;

import java.util.ArrayList;

public class CheckAdapter extends ArrayAdapter<CheckCode> {


    private static final String TAG = "FansAdapter";

    private String attractions_id;

    private Context context;

    private Activity activity;

    public CheckAdapter(Context context, ArrayList<CheckCode> members)
    {
        super(context,0, members);
        this.context = context;
        this.activity = (Activity) context;
    }
    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        CheckCode checkCode = getItem(position);

        if(convertView == null)
        {
            convertView = LayoutInflater.from(getContext()).inflate(R.layout.item_check, parent, false);
        }

        TextView check_screen_ticket_name = convertView.findViewById(R.id.check_screen_ticket_name);
        TextView check_ticket_number = convertView.findViewById(R.id.check_ticket_number);
        TextView check_number = convertView.findViewById(R.id.check_number);
        TextView check_code_id = convertView.findViewById(R.id.check_code_id);
        TextView check_use_time = convertView.findViewById(R.id.check_use_time);
        ImageView check_img = convertView.findViewById(R.id.check_img);
        Button to_screen = convertView.findViewById(R.id.to_screen);
        check_screen_ticket_name.setText(checkCode.getAttractionsName());
        check_number.setText(checkCode.getUu_code());
        check_code_id.setText("" + checkCode.getId());
        attractions_id = String.valueOf(checkCode.getAttractions_id());
        check_ticket_number.setText(checkCode.getTickets_number() +  "张");
        check_use_time.setText("使用时间（当地时间）：" + checkCode.getPlaytime());
        if (checkCode.getQr_code_image() != null){
            if(!checkCode.getQr_code_image().equals("")){
                NetworkGlideImageLoader.getInstance().displayImage((Activity) context, checkCode.getQr_code_image(),check_img,0,0);
            }
        }
        to_screen.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, ScreenDetailsActivity.class);
                intent.putExtra("attractions_id",attractions_id);
                activity.startActivity(intent);
            }
        });

        return convertView;
    }

}



